package com.cacho.s2b.lesson.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Description 日期和时间相关工具类
 * @Author LingWei
 * @date 2024/06/28
 **/
public class TimeUtils {
    public static void main(String [] args){
        Date date = new Date();
        addDateTimeStr(date,"yyyy-MM-ddTHH:mm:ss","GMT+3",365);
    }

    /**
     * @param days
     *      (int)
     */
    public static String addDateTimeStr(Date date,String format,String timezone,int days){
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        // 设定时区
        sdf.setTimeZone(TimeZone.getTimeZone(timezone));
        Calendar c = Calendar.getInstance();
        // 添加或者减少天
        c.add(Calendar.DATE, days);
        Date currentDatePlus = c.getTime();
        return sdf.format(currentDatePlus);
    }
}
